<!--  -->
<template>
    <div class="user">
      <div class="h50">
          <my-tab-bar
            title="账号管理"
            left-arrow
            @click-left = "onClickLeft"
          ></my-tab-bar>
        </div>
        <div class="input-item">
            <van-field v-model="nickName" label="昵称" />
            <van-field v-model="introduceSign" label="个性签名" />
            <van-field v-model="password" type='password' label="修改密码" />
          </div>
          <van-button class="save-btn" color="#1baeae" type="primary" @click="save" block>保存</van-button>
          <!-- <van-button class="save-btn" color="#1baeae" type="primary" @click="logout" block>退出登录</van-button> -->
     
      
      <van-button type="danger"   block @click="logout" class="save-btn">退出登录</van-button>
  
    </div>
  </template>

<script>
    import {
        EditUserInfo,
        logout,
        getUserInfo
    } from '@/api/index';
    import {
        Dialog,
        Toast
    } from "vant";
    import md5 from "js-md5";
    export default {
        data() {
            return {
                nickName: '',
                introduceSign: '',
                password: ''
            }

        },
        created() {
            // this.user = JSON.parse(localStorage.getItem("userData"));
            // console.log(JSON.parse(localStorage.getItem("userData")))
        },
        async mounted() {
            const {
                data
            } = await getUserInfo();
            this.nickName = data.nickName;
            this.introduceSign = data.introduceSign;
        },
        methods: {
            onClickLeft() {
                this.$router.back()
            },
            async save() {
                const params = {
                    introduceSign: this.introduceSign,
                    nickName: this.nickName,
                    passwordMd5: md5(this.password)
                }
                const {
                    data
                } = await EditUserInfo(params);
                Toast.success('保存成功')
            },
            logout() {
                let that = this;
                // QC.Login.signOut()      //qq退出登录
                // this.$message.info('qq退出登录')
                Dialog.confirm({
                    title: '确认退出吗？'
                }).then(() => {
                    logout().then(res => {
                        if (res.resultCode == 200) {
                            Toast('退出成功')
                            window.location.href = '/'
                        }
                    })
                })
            }

        }
    }
</script>
<style lang='less' scoped>
    .seting-box {
        .input-item {
            margin-top: 44px;
        }
        .save-btn {
            width: 80%;
            margin: 20px auto;
        }
    }
</style>